﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using System.Threading.Tasks;
using VisionCloud.Domain.File.Model;
using VisionCloud.Domain.Filters;
using VisionSurface.Service.Sys;

namespace VisionSurface.Web.Controllers.Sys
{
    [ApiVersion("1.0")]
    [ApiAuthorize(PolicyEnum.RequireRolePermission)]
    [ApiExplorerSettings(GroupName = "文件管理")]
    [Route("api/sys/[controller]/[Action]")]
    [AllowAnonymous]
    public class FileController : ApiBaseController
    {
        public UploadFileService UploadFileService { get; set; }

        /// <summary>
        /// 秒传验证
        /// </summary>
        [HttpGet]
        [SwaggerResponse(0, null, typeof(VerifyResponse))]
        public async Task<VerifyResponse> Verify([FromQuery] UploadFileBaseDto dto)
        {
            return await UploadFileService.Verify(dto);
        }

        /// <summary>
        /// 合并所有分片
        /// </summary>
        [HttpGet]
        [SwaggerResponse(0, null, typeof(MergeResponse))]
        public async Task<MergeResponse> Merge([FromQuery] UploadFileBaseDto dto)
        {
            return await UploadFileService.Merge(dto);
        }

        /// <summary>
        /// 上传分片
        /// </summary>
        [HttpPost]
        [SwaggerResponse(0, null, typeof(UploadResponse))]
        public async Task<UploadResponse> Upload([FromQuery] PartUploadDto upload)
        {
            var dataContent = HttpContext.Request.Body;
            return await UploadFileService.UploadPart(upload, dataContent);
        }
    }
}